import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

public class RedisList {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");

        try (Jedis jedis = jedisPool.getResource()) {
//            test1(jedis);

//            test2(jedis);

//            test3(jedis);

            test4(jedis);
        }
    }

    public static void test4(Jedis jedis) {
        System.out.println("len: " + jedis.llen("key1"));
    }

    public static void test3(Jedis jedis) {
        jedis.flushAll();

        List<String> list = jedis.blpop(100, "key1");
        System.out.println(list.get(0) + ": " + list.get(1));
    }

    public static void test2(Jedis jedis) {
//        jedis.flushAll();

        String value1 = jedis.lpop("key1");
        System.out.println(value1);

        String values2 = jedis.rpop("key2"); // redis6 及以上才能够使用 count
        System.out.println(values2);

        System.out.println(jedis.lpop("key3"));
    }

    public static void test1(Jedis jedis) {
        jedis.flushAll();

        jedis.lpush("key1", "111", "222", "333");
        List<String> values1 = jedis.lrange("key1", 0, -1);
        System.out.println(values1);

        jedis.rpush("key2", "111", "222", "333");
        List<String> values2 = jedis.lrange("key2", 0, -1);
        System.out.println(values2);
    }
}
